hbridge18 2.2.1
Loading...
Searching...
No Matches
hbridge18


H-Bridge 18 Click

H-Bridge 18 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Jan 2025.
  • Type : SPI type

Software Support

Example Description

This example demonstrates the operation of the H-Bridge 18 Click board, which provides control over two DC motors using an H-Bridge driver. The application initializes the board and alternates between different motor states, including forward, reverse, coast, and braking, to demonstrate bidirectional motor control.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.HBridge18

Example Key Functions

Application Init

Initializes the logger and the H-Bridge 18 Click board. Configures the motor driver to the default settings, preparing it for operation.

void application_init ( void )
{
log_cfg_t log_cfg;
hbridge18_cfg_t hbridge18_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
hbridge18_cfg_setup( &hbridge18_cfg );
if ( SPI_MASTER_ERROR == hbridge18_init( &hbridge18, &hbridge18_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( HBRIDGE18_ERROR == hbridge18_default_cfg ( &hbridge18 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define HBRIDGE18_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition hbridge18.h:201
@ HBRIDGE18_ERROR
Definition hbridge18.h:263
void application_init(void)
Definition main.c:41
#define MIKROBUS_POSITION_HBRIDGE18
Definition main.c:35

Application Task

Alternates motor states in a sequence to demonstrate different control functionalities. The motors are set to move forward and reverse, followed by coasting and braking, repeating the cycle continuously.

void application_task ( void )
{
log_printf( &logger, " Motor 0: Forward\r\n" );
log_printf( &logger, " Motor 1: Reverse\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor 0: Coast\r\n" );
log_printf( &logger, " Motor 1: Brake LS\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor 0: Reverse\r\n" );
log_printf( &logger, " Motor 1: Forward\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf( &logger, " Motor 0: Brake HS\r\n" );
log_printf( &logger, " Motor 1: Coast\r\n\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
#define HBRIDGE18_MOTOR_STATE_FORWARD
Definition hbridge18.h:169
#define HBRIDGE18_MOTOR_STATE_BRAKE_HS
Definition hbridge18.h:172
#define HBRIDGE18_MOTOR_STATE_COAST
H-Bridge 18 motor state setting.
Definition hbridge18.h:168
#define HBRIDGE18_MOTOR_STATE_REVERSE
Definition hbridge18.h:170
#define HBRIDGE18_MOTOR_1
Definition hbridge18.h:162
#define HBRIDGE18_MOTOR_STATE_BRAKE_LS
Definition hbridge18.h:171
#define HBRIDGE18_MOTOR_0
H-Bridge 18 motor selection setting.
Definition hbridge18.h:161
void application_task(void)
Definition main.c:77

Note

Ensure proper power supply (4.5V-32V, depending on motor specifications) and motor connections (motor 0: O1-O2; motor 1: O3-O4) before running the example.

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.